/**
 * 
 */
package com.geekteam.manga.Utils;

import com.geekteam.imageloader.cache.disc.naming.Md5FileNameGenerator;
import com.geekteam.imageloader.core.ImageLoader;
import com.geekteam.imageloader.core.ImageLoaderConfiguration;

import android.app.Application;

/**
 * @author MtRol
 * 
 */
public class MangaApplication extends Application {

	private static MangaApplication instance;

	public MangaApplication() {
		instance = this;
	}

	public static MangaApplication getInstance() {
		if (instance == null) {
			synchronized (MangaApplication.class) {
				if (instance == null) {
					instance = new MangaApplication();
				}
			}
		}

		return instance;
	}

	@Override
	public void onCreate() {
		super.onCreate();

		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
				getApplicationContext()).threadPoolSize(3)
				.threadPriority(Thread.NORM_PRIORITY - 2)
				.memoryCacheSize(1500000).denyCacheImageMultipleSizesInMemory()
				.discCacheFileNameGenerator(new Md5FileNameGenerator())
				.enableLogging().build();
		ImageLoader.getInstance().init(config);
	}
	
	@Override
	public void onLowMemory() {
		super.onLowMemory();
		ImageLoader.getInstance().clearMemoryCache();
	}
}
